package com.wind.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wind.beans.updateListBean;
import com.debug.soblogin.R;

import java.util.ArrayList;
import java.util.List;

public class UpdateListAdapter extends RecyclerView.Adapter<UpdateListAdapter.InnerHolder>{
    private final List<updateListBean> mData;
    public UpdateListAdapter(ArrayList<updateListBean> data) {
        this.mData = data;
    }
    @NonNull
    @Override
    public UpdateListAdapter.InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_update_list, null);
        return new InnerHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull UpdateListAdapter.InnerHolder holder, int position) {
        holder.setData(mData.get(position), position);
    }

    @Override
    public int getItemCount() {
        if (mData != null) {
            return mData.size();
        }
        return 0;
    }

    public class InnerHolder extends RecyclerView.ViewHolder {
        private final TextView mUpdate_date;
        private final TextView mUpdate_content;
        private int mPosition;
        public InnerHolder(@NonNull View itemView) {
            super(itemView);
            mUpdate_date = itemView.findViewById(R.id.update_date);
            mUpdate_content = itemView.findViewById(R.id.update_content);
        }

        public void setData(updateListBean updateListBean, int position) {
            this.mPosition = position;
            mUpdate_date.setText(updateListBean.date);
            mUpdate_content.setText(updateListBean.content);
        }
    }
}
